<template>
  <div class="sort">
    <heads/>
    <van-loading size="24px" vertical v-if="!list"></van-loading>
    <div class="sort_item"  v-for="(item,index) in list" :key="item.name" >
      <div class="sort_nav">
        <div class="sort_title">
          <span class="icon"></span><span>{{item.name}}</span>
        </div>
        <div class="sort_btn"></div>
      </div>
      <div class="sort_box" >
        <div class="item" v-for="item in listData[index]" :key="item.name" @click="goClassData(item.url)">{{item.name}}</div>
        <van-loading size="24px" vertical v-if="!listData[index]"></van-loading>
      </div>
    </div>
  </div>
</template>

<script>
import heads from '../components/heads.vue';
import {getClass,getClassList} from "../api/classify"
export default {
  data(){
    return{
      list:null,
      listData:[]
    }
  },
  components: { heads },
  methods:{
    goClassData(url){
      this.$router.push({path:'/about/classData',query:{url:url}})
    }
  },
  watch:{
    list(){
       this.list.forEach(item=>{
      getClassList(item.node[0].url).then(data=>{
        this.listData.push(data.list[0].labels);
        console.log(this.listData)
      })
    })
    }
  },
  created(){
    getClass().then(data=>{
      this.list=data.books
    })
   
  }
  
  };

</script>

<style lang="less">
.sort {
  overflow: hidden;
  .sort_item {
    margin-top: 15px;
    background-color: #fff;
    .sort_nav {
      display: flex;
      justify-content: space-between;
      color: #4c4c4c;
      font-size: 14px;
      height: 25px;
      border-top: 1px solid #dfdfdf;
      border-bottom: 1px solid #dfdfdf;
      padding: 11px 8px 0;
      line-height: 14px;
      .icon {
        height: 14px;
        width: 8px;
        float: left;
        background: #5e5e5e;
        border-radius: 2px;
        margin-right: 7px;
        background: #ff4643;
      }
    }
    .sort_box {
      display: flex;
      flex-wrap: wrap;
      text-align: center;
      .item {
        width: 25%;
        margin: 8px 0;
        color: #5e5e5e;
        font-size: 14px;
        position: relative;
        &:not(&:nth-child(4n))::after {
          content: "";
          width: 1px;
          height: 70%;
          display: block;
          position: absolute;
          top: 0;
          bottom: 0;
          /* left: 51%; */
          left: 92px;
          margin: auto;
          background-color: #ccc;
        }
      }
    }
  }
}
</style>